<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use App\Helpers\DatabaseHelper;

class CreateDormRatingMainsTable extends Migration
{
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('dorm_rating_mains', function (Blueprint $table) {
			$table->increments('id');
			$table->integer('company_id')->nullable();
			$table->unsignedInteger('user_id')->nullable()->comment('创建人');
			$table->integer('dorm_id')->unsigned();
			$table->integer('period_id')->unsigned();
			$table->float('get_score')->nullable()->comment('');
			$table->float('total_score')->nullable()->comment('');
			$table->boolean('is_closed')->default(false)->comment('是否已关闭');
			$table->string('remark')->nullable()->comment('备注');
			$table->timestamps();
			$table->unique(['dorm_id', 'period_id']);
		});
		DatabaseHelper::createTriggers('dorm_rating_mains', 'dorms');
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('dorm_rating_mains');
	}
};
